package com.csun.nusing.presenter;

import android.content.Context;
import android.util.Log;

import com.csun.nusing.bean.UrlBean;
import com.csun.nusing.bean.jsonbean.BaseJsonBean;
import com.csun.nusing.bean.jsonbean.ResignPhoneCodeJsonBean;
import com.csun.nusing.presenter.inter.IForgetPsd;
import com.csun.nusing.util.ToastUtil;
import com.google.gson.Gson;
import com.home.administrator.okhttplibrary.IOkTaskCallback;
import com.home.administrator.okhttplibrary.OkHttpTask;
import com.home.administrator.okhttplibrary.OkHttpTask.OkHttpTaskBuidler.OkType;

import java.util.HashMap;

/**
 * 忘记密码界面的p层 ClassName: ResignPresenter
 * 
 * @Description: TODO
 * @author fzq
 * @date 2017-10-25
 */
public class ForgetPsdPresenter extends BasePresenter<IForgetPsd> {

	protected String codekey;

	public ForgetPsdPresenter(IForgetPsd view) {
		super(view);
	}

	/**
	 * 获取验证吗
	 * 
	 * @Description: TODO
	 * @param @param context
	 * @param @param phone
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-10-30
	 */
	public void getPhoneCode(final Context context, String phone) {
		HashMap<String, String> param = new HashMap<String, String>();
		param.put("phone", phone);
		param.put("codeType", "2");
		OkHttpTask.newInstance(context).post(param, OkType.form)
				.enqueue(new IOkTaskCallback() {
					@Override
					public void onSuccess(String result) {
						if (result != null) {
							Log.e("fzq", "---------- " + result);
							Gson gson = new Gson();
							ResignPhoneCodeJsonBean resigncodeJsonBean = gson
									.fromJson(result,
											ResignPhoneCodeJsonBean.class);
							if (resigncodeJsonBean != null) {
								if (resigncodeJsonBean.isStatus()) {
									codekey = resigncodeJsonBean.getData().getPhone();
									getViewRef().sendCode(codekey);
								} else {
									ToastUtil.showMessage(context,
											resigncodeJsonBean.getMessage());
								}
							}
						}
					}
				}).start(UrlBean.RESIGNCODEURL);

	}

	/**
	 * 移动端注册
	 * 
	 * @Description: TODO
	 * @param @param context
	 * @param @param phoneCode
	 * @param @param msgcode
	 * @param @param password
	 * @param @param repassword
	 * @param @param string
	 * @return void
	 * @throws
	 * @author fzq
	 * @date 2017-10-30
	 */
	public void resign(final Context context, String phoneCode, String msgcode,
			String password, String repassword, String string) {
		HashMap<String, String> param = new HashMap<String, String>();
		param.put("codekey", codekey);
		param.put("code", msgcode);
		param.put("password", password);
		param.put("repassword", repassword);
		OkHttpTask.newInstance(context).post(param, OkType.form)
				.enqueue(new IOkTaskCallback() {
					@Override
					public void onSuccess(String result) {
						if (result != null) {
							Log.e("fzq", "---------- " + result);
							Gson gson = new Gson();
							BaseJsonBean jsonBean = gson.fromJson(result,
									BaseJsonBean.class);
							if (jsonBean != null) {
								ToastUtil.showMessage(context,
										jsonBean.getMessage());
							}
						}
					}
				}).start(UrlBean.MODIFYPSDURL);
	}

}